package com.sinocare.project.system.service.impl;


import com.sinocare.project.common.domain.SystemAccount;
import com.sinocare.project.common.dopackage.SystemDo;
import com.sinocare.project.common.utils.Code;
import com.sinocare.project.common.utils.MD5;
import com.sinocare.project.common.vo.SystemVo;
import com.sinocare.project.system.dao.SystemMapper;
import com.sinocare.project.system.service.SystemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SystemServiceImpl implements SystemService {

    @Resource
    private SystemMapper systemMapper;

    @Override
    public List<SystemDo> query(SystemVo systemVo) {
        return systemMapper.query(systemVo);
    }

    @Override
    public int update(SystemDo systemDo) {
        return systemMapper.update(systemDo);
    }

    @Override
    public int add(SystemAccount systemAccount) {

        systemAccount.setCustomerCode(Code.AutoGenCode());
        systemAccount.setPassword("123456");
        String s = MD5.md5AndSalt(systemAccount.getPassword(),1024);
        String[] split = s.split(",");
        systemAccount.setPassword(split[0]);
        systemAccount.setSalt(split[1]);

        return systemMapper.add(systemAccount);
    }

    @Override
    public int addrole(SystemAccount systemAccount) {
        return systemMapper.addrole(systemAccount);
    }

    @Override
    public int addstore(SystemAccount systemAccount) {
        return systemMapper.addstore(systemAccount);
    }
}
